using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class info : MonoBehaviour  {
	public int [,] grid;
	public int siX,siY;
	public int pX,pY;
	public drawTiles draws;
	public Guis guis;
	// Use this for initialization
	void Start () {
	DontDestroyOnLoad(gameObject);
	}
	
	// Update is called once per frame
	void Update () {
		
		
		if(draws.on)
	{
	
	if (Input.GetKeyDown(KeyCode.N))
			{
				guis.randoDun();
				
			}
		
	if (Input.GetKeyDown(KeyCode.UpArrow))
		    {
			if(grid[pX,pY-1]==2)
			{
			pY-=1;	
			}
			}
	if (Input.GetKeyDown(KeyCode.DownArrow))
		    {
			if(grid[pX,pY+1]==2)
			{
			pY+=1;	
			}
			}
		if (Input.GetKeyDown(KeyCode.RightArrow))
		    {
			if(grid[pX+1,pY]==2)
			{
			pX+=1;	
			}
			}
		if (Input.GetKeyDown(KeyCode.LeftArrow))
		    {
			if(grid[pX-1,pY]==2)
			{
			pX-=1;	
			}
			}
			
		}
		
	}
	
	public void fillGrid(float sizX,float sizY)
	{
		siX = (int) sizX;
		siY = (int) sizY;
		grid = new int[(int)sizX,(int)sizY];
		for(int i = 0;i<sizX;i++)
		{
		for(int j = 0;j<sizY;j++)
			{
			grid[i,j] = 0;	
			}
		}
		
	}
	
	public void putRooms(List <Rectangles> roomList)
	{
	for (int i = 0; i<	roomList.Count;i++)
		{
			
			
		for(int j=0;j< roomList[i].width;j++)
			{
				grid[(int)roomList[i].x+j,(int)roomList[i].y] = 1;	
			}
			
			for(int k = 1; k< roomList[i].height;k++)
			{
				grid[(int) roomList[i].x,(int) roomList[i].y+k] = 1;
				
				for(int l = 1;l<roomList[i].width-1;l++)
				{
					grid[(int) roomList[i].x+l,(int) roomList[i].y+k] = 2;
					
				}
				
				grid[(int) roomList[i].x+(int)roomList[i].width-1,(int) roomList[i].y+k] = 1;
				
				
			}
		
		for(int j=0;j< roomList[i].width;j++)
			{
				grid[(int) roomList[i].x+j,(int) roomList[i].y+(int) roomList[i].height] = 1;	
			}
		}
	}
	
	public void putHallways(List <Rectangles> roomList)
	{
	for (int i = 0; i<	roomList.Count;i++)
		{
		if (roomList[i].width==3)
			{
				for(int k = 0; k<roomList[i].height;k++)
				{
					grid[(int)roomList[i].x,(int)roomList[i].y+k] = 1;
					grid[(int)roomList[i].x+1,(int)roomList[i].y+k] = 2;
					grid[(int)roomList[i].x+2,(int)roomList[i].y+k] = 1;
					
				}
			
			grid[(int)roomList[i].x+1,(int)roomList[i].y] = 2;
			grid[(int)roomList[i].x+1,(int)roomList[i].y+(int)roomList[i].height] = 2;
				
				
			}
			
			else
			{
				for(int j=0;j< roomList[i].width;j++)
			{
				grid[(int)roomList[i].x+j,(int)roomList[i].y] = 1;	
			}
				
				for(int j=0;j< roomList[i].width;j++)
			{
				grid[(int)roomList[i].x+j,(int)roomList[i].y+1] = 2;	
			}
				
				
				for(int j=0;j< roomList[i].width;j++)
			{
				grid[(int)roomList[i].x+j,(int)roomList[i].y+2] = 1;	
			}
				
				
				grid[(int)roomList[i].x-1,(int)roomList[i].y+1] = 2;
			grid[(int)roomList[i].x+(int)roomList[i].width,(int)roomList[i].y+1] = 2;
				
				
			}
			
			
		}
		
	}
	
	public void placePlayer()
	{
		for(int i = 0;i<20;i++)
		{
		for	(int k = 0;k<20;k++)
			{
			if (grid[i,k] == 2)	
				{
				pX = i;
				pY = k;
				return;
				}
			}
			
		}
		
		
	}
}
